<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script text="javascript">

    // const arr = [3,2,1,4,5]
    // let temp = arr[2]
    // arr[2] = arr[0]
    // arr[0] = temp
    // 将数组中的  元素1  与  元素3 调换位置
        const arr1 = [3,2,1,4,5];
        [arr1[0],arr1[2]] = [arr1[2],arr1[0]]
        console.log(arr1);


    // 使用冒泡排序（从大到小）：  [90,65,78,66,48,39,92,73]  使用数组解构的方法交换变量
        const arr2 = [90,65,78,66,48,39,92,73];
        var [a,b,c,d,e,f,g,h] = arr2;

        for(var i = 0;i < arr2.length-1;i++){
            for(var j = 0;j < arr2.length-1-i;j++){
                if(arr2[j] < arr2[j+1]){
                    [arr2[j],arr2[j+1]] = [arr2[j+1],arr2[j]]
                }
            }
        }
        console.log(arr2);

    // var text =
    // 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'
    // //将上述字符串去除标点空格后统计有多少个单词
        var str = "I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.";
        const arr3 = str.split("");
        var rel;
        for(var i = 0;i <= arr3.length;i++){
            if(arr3[i] == ',' || arr3[i] == '.'){
                arr3.splice(i,1);
            }
            rel += arr3[i];
        }
        console.log(rel.split(" ").length);

    // const arr = [87,85,74,70,65,59,43]
    // 1.移除第一个元素87，并在开头添加 元素86
    // 2.移除最后一个元素43， 并在末尾添加1
    // 3.在 70 65 之间插入 元素 68
    // 4.删除元素65
    // 5.使用map返回一个新的数组new_arr，要求新数组new_arr比原来数组大2
    // 6.筛选数组new_arr返回new_arr1,要求new_arr1: 能被2整除
        const arr4 = [87,85,74,70,65,59,43]
        //1
        arr4.shift();
        arr4.unshift(86);
        //2
        arr4.pop();
        arr4.push(1);
        //3
        arr4.splice(4,0,68);
        //4
        for(var i = 0;i < arr4.length-1;i++){
            if(arr4[i] == 65){
                arr4.splice(i,1);
            }
        }
        //5
        const new_arr = new Map();
        for(var i = 0;i < arr4.length;i++){
            new_arr[i] = arr4[i] + 2;
        }
        //6
        const new_arr1 = new Map();
        for(var i = 0;i < arr4.length;i++){          
            if(new_arr[i] % 2 == 0){
                new_arr1[i] = new_arr[i];
            }
        }

        console.log(arr4);
        console.log(new_arr);
        console.log(new_arr1);


    </script>
</body>
</html>